/*
 * AALLocatorItem.c
 *
 *  Created on: 17.05.2011
 *      Author: sili
 */

#include "AALLocatorItem.h"

static log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("at.sili.aalsystem.model.AALLocatorItem"));

AALLocatorItem::AALLocatorItem(const int _id, Controller * _controller)
			   :AALItem(_id, _controller){
	AAL_TRACE(logger,"Constructor globalId:%d", AALItem::globalId);
	this->currentValue = 0;
	this->visibility = 0;
	this->type.clear();
	this->type.append("locator");
}

AALLocatorItem::~AALLocatorItem() {
	AAL_TRACE(logger,"Destructor globalId:%d", AALItem::globalId);
}

void AALLocatorItem::setHotkey(int _hotkey){
	// Don't do anything. I'm a locator and can't be accessed by an hotkey
}

void AALLocatorItem::changeValue(int _value){
	AAL_DEBUG(logger,"ActuatorId:%d value:%d", this->getId(), _value);
	this->currentValue = _value;
	this->currentValue == 0 ? this->visibility = 0 : this->visibility = 100;
	this->controller->publish(doReaload,"",this);
}

void AALLocatorItem::visualizeSelf(Visualizer * _visualizer, AALAction * _action){

	if( _action->type == doInfo ||
		_action->type == doWarn ||
		_action->type == doAlarm){
		AALItem::visualizeSelf(_visualizer, _action);
		return;
	}

	// get parent aalItem
	AALItem * parent = this->getParent();
	if(parent){
		// Parent does the default stuff
		parent->visualizeSelf(_visualizer, _action);
	}

	const cFont * font = cFont::GetFont(fontOsd);
	if(_visualizer->getInfoPane() != NULL){
		_visualizer->getInfoPane()->Clear();

		uint32_t bgColor = _visualizer->getBackgroundColorForPane(DrawPane::infoPaneType);
		_visualizer->getInfoPane()->colorBg = bgColor;

		// draw image
		AALSize wishSize;
		wishSize.width = _visualizer->getInfoPane()->area.width / 5.0;
		wishSize.height = _visualizer->getInfoPane()->area.height * 0.95;

		this->resize(&wishSize, true);

		AALLocation location;
		location.left = ((_visualizer->getInfoPane()->area.width - this->image.columns()));
		location.top = ((_visualizer->getInfoPane()->area.height - this->image.rows()) / 2.0);
		this->renderImage(_visualizer->getInfoPane(), & location , 1, 0);

		// draw text
		this->textArea.top = 10;
		this->textArea.left = 10;
		this->textArea.width = _visualizer->getInfoPane()->area.width - 2 * this->textArea.left;
		this->textArea.height = (_visualizer->getInfoPane()->area.height - 2 * this->textArea.top) / 3.0;
		this->textArea.width -= this->image.columns();

		string textline(this->name.c_str());
		textline.append(" (");
		textline.append(this->parent->getName());
		textline.append(")");
		_visualizer->getInfoPane()->DrawText(this->textArea, textline.c_str(), _visualizer->getTextColor(), clrTransparent, font);
	}
}
